package com.espeaker.sdk.api;

import android.os.Handler;

import com.espeaker.sdk.ESpeakerParameters;
import com.espeaker.sdk.Constants;
import com.espeaker.sdk.utils.Base64Util;

public class RegisterApi extends MiaoApi {
	/*
	 * 获取短信验证码
	 */
	public void getVerCode(final String phoneNum, final String is_regist,final Handler handler) {
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("phone_number", phoneNum,true);
					params.add("is_regist", is_regist,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_GET_ACTIVE_CODE,
							params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.REGISTERAPI_GETVERCODE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 找回密码
	 */
	public void getVerCode_FindPassword(final String phoneNum,final Handler handler) {
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("phone_number", phoneNum,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_GET_ACTIVE_CODE,
							params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.REGISTERAPI_GETVERCODE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 验证短信验证码
	 */
	public void verfiyVerCode(final String phoneNum,final String verCode, final Handler handler) {
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("phone_number", phoneNum,true);
					params.add("active_code", verCode,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_VERIFIY_ACTIVE_CODE,
							params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.REGISTERAPI_VERIFYVERCODE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 设置密码
	 */
	public void setPassword(final String phoneNum,final String password, final Handler handler) {
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					String encodePassword = Base64Util.encodeStr(password);
					encodePassword = Base64Util.encodeStr(encodePassword);
					params.add("phone_number", phoneNum,true);
					params.add("password", encodePassword,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_SET_PASSWORD,
							params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.REGISTERAPI_SETPASSWORD, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
}
